package com.haoma.controller;

import com.haoma.annotation.RequestCount;
import com.haoma.entity.TalkUser;
import com.haoma.result.Result;
import com.haoma.service.TalkService;
import com.haoma.vo.AllTalkVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * Description: 说说的相关接口
 */
@RestController
@RequestMapping("/web/talk")
@CrossOrigin

public class TalkController {

    @Autowired
    private TalkService talkService;

    /**
     * 获取所有的说说详情
     *
     * @return
     */
    @RequestCount
    @GetMapping("/list")
    public Result getTalk() {
        List<AllTalkVo> talkVoList = talkService.getTalkList();
        return Result.success(talkVoList);
    }

    /**
     * 存储说说用户
     *
     * @param talkUser
     * @return
     */
    @RequestCount
    @PostMapping("/user")
    public Result saveUserTalk(@RequestBody TalkUser talkUser) {
        Integer id = talkService.saveUserTalk(talkUser);
        return Result.success(id);
    }

    /**
     * 上传说说用户头像
     *
     * @param multipartFile
     * @return
     */
    @RequestCount
    @PostMapping("/fileUpload")
    public Result fileUpload(@RequestParam("file") MultipartFile multipartFile) {
        String fileUrl = talkService.fileUpload(multipartFile);
        return Result.success(fileUrl);
    }

    /**
     * 查询用户是否已经点赞了
     *
     * @param id
     * @return
     */
    @RequestCount
    @GetMapping("/islike/{id}/{talkId}")
    public Result getIsLike(@PathVariable Integer id, @PathVariable Integer talkId) {
        Integer isLiked = talkService.getIsLike(id, talkId);
        return Result.success(isLiked);
    }

    /**
     * 用户点赞
     *
     * @param id
     * @param status
     * @return
     */
    @RequestCount
    @PutMapping("/liked/{id}/{status}/{talkId}")
    public Result updateLike(@PathVariable Integer id
            , @PathVariable Integer status,
                             @PathVariable Integer talkId) {
        talkService.updateLike(id, status, talkId);
        return Result.success();
    }


    /**
     * 发起评论
     *
     * @param id     用户id
     * @param talkId 说说id
     * @return
     */
    @RequestCount
    @PostMapping("/comment/{id}/{talkId}")
    public Result comment(@PathVariable Integer id, @PathVariable Integer talkId, String remork) {
        talkService.comment(id, talkId, remork);
        return Result.success();
    }
}
